package org.example.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.domain.User;
import org.example.service.UserService;
import org.example.mapper.UserMapper;
import org.example.util.JwtToken;
import org.example.util.Result;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;

/**
* @author 86150
* @description 针对表【t_user】的数据库操作Service实现
* @createDate 2024-07-10 18:42:56
*/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
    implements UserService{
@Resource
private UserMapper userMapper;
    @Override
    public Result login(User user) {
        User user1 = userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getUsername, user.getUsername()));
        if (user1==null){
            return  Result.ERROR("用户名不存在");
        }
        if (!user1.getPassword().equals(user.getPassword())){
            return Result.ERROR("密码错误");
        }
        HashMap<String, Object> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("token",user1.getUid());
        String token = JwtToken.createJetToken(objectObjectHashMap);
        return Result.OK(token);

    }


}




